package as.myapplication;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tm on 2017/4/1.
 */

public class MyFragmentPagerAdapter extends FragmentStatePagerAdapter {


   //fragment
   private List<Fragment> fragments ;

    private String[] contentTitles;

    //参数二 ：在string.xml的string的id
    public MyFragmentPagerAdapter(FragmentManager fm, List<Fragment> list,String[] title) {
        super(fm);
        this.fragments = list;
        this.contentTitles =title;

    }

    @Override
    public Fragment getItem(int position) {

        // 根据不同posistion 返回 Fragment
        return fragments.get(position);
    }

    @Override
    public int getCount() {

        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        //返回数据与Tablayout关联
        return contentTitles[position];
    }
}
